package com.example.designpatterns.visitor;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
public class ObjectStructure {

    private List<Element> elements;

    public ObjectStructure() {
        this.elements = new ArrayList<>();
    }

    public void add(Element element) {
        this.elements.add(element);
    }

    public Element get(Integer index) {
        return this.elements.get(index);
    }

    public void remove(Element element) {
        this.elements.remove(element);
    }

    /**
     * 访问对象内元素
     *
     * @param visitor
     */
    public void accept(Visitor visitor) {
        for (Element element : this.elements) {
            element.accept(visitor);
        }
    }
}

